package com.deparse.mydialog;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.deparse.mydialog.animation.AndroidAnimation;
import com.deparse.mydialog.common.BaseActivity;
import com.deparse.mydialog.dialog.AndroidDialog;
import com.deparse.mydialog.listview.HideListTitleActivity;
import com.deparse.mydialog.listview.SwipeRefreshLayout;
import com.deparse.mydialog.listview.ListAttributeActivity;
import com.deparse.mydialog.shadow.TextShaow;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {
    private ListView listView;
    private AdapterList adapterList;
    private List<Class<?>> listData = new ArrayList<>();
    private LayoutInflater layoutInflater;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        layoutInflater = LayoutInflater.from(this);
        listView = (ListView) findViewById(R.id.listView);
        listData.clear();
        listData.add(AndroidDialog.class);
        listData.add(AndroidAnimation.class);
        listData.add(SwipeRefreshLayout.class);
        listData.add(ListAttributeActivity.class);
        listData.add(HideListTitleActivity.class);
        listData.add(TextShaow.class);


        adapterList = new AdapterList();
        listView.setAdapter(adapterList);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(listData.get(position));
            }
        });

    }

    private class AdapterList extends BaseAdapter {

        @Override
        public int getCount() {
            return listData.size();
        }

        @Override
        public Object getItem(int position) {
            return listData.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = layoutInflater.inflate(R.layout.item_main_list, null);
            TextView activity_name = (TextView) convertView.findViewById(R.id.activity_name);
            activity_name.setText(listData.get(position).getSimpleName());
            return convertView;
        }
    }
}
